const Index = {
	files: null,
	fileType: [ 'csv' ],
	includeFileType({ name }){ return this.fileType.includes( name.substr( name.lastIndexOf('.') + 1 ) ) },
	open(callback){
		let $upload = document.querySelector('#jzer-upload-csv')
		if(!$upload){
			$upload = document.createElement('input')
			// if( mul ) { $upload.setAttribute('multiple','multiple') }
			$upload.setAttribute('type','file')
		}
		$upload.click()
		$upload.onchange = ({ target:{ files } }) => {
			if(!this.includeFileType(files[0])) return window.$fn.msg.warning('只能上传 csv 文件')
			this.files = files
			const fileReader = new FileReader()
			fileReader.onload = ({ target:{ result } })=>{
				callback?.(result)
			}
			fileReader.readAsText(files[0])
		}
	}
}

export default Index